﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LotteryPanel : MonoBehaviour
{
    public Text m_Title;
    public GameObject m_BoughtNumberPanel;
    public Text m_NumberTextPerfab;
    public NumberLine m_NumberLine;
    void Start()
    {
        int today = UtilsGame.GetSeedToday();
        m_Title.text = "第 "+today+" 期地联福利彩票";

        for(int i=0; i<Player.Instance.m_LotteryCurTerm.Count; ++i)
        {
            var text = Instantiate(m_NumberTextPerfab);
            text.text = Player.Instance.m_LotteryCurTerm[i].ToString().PadLeft(4, '0'); ;
            text.transform.SetParent(m_BoughtNumberPanel.transform);
            text.transform.localScale = new Vector3(1,1,1);
        }
        m_NumberLine.CallbackBuyNumber = OnBuyNumber;
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    public void OnBuyNumber(int number)
    {
        for(int i=0; i<Player.Instance.m_LotteryCurTerm.Count; ++i)
        {
            if(Player.Instance.m_LotteryCurTerm[i] == number)
            {
                MessageShow.Instance.Messaage("买两个一样的号码也不会给双倍的奖金哦！", new Vector4(0.6f, 0.6f, 0.2f, 1));
                return;
            }
        }
        if (Player.Instance.Money < 100)
        {
            MessageShow.Instance.Messaage("你钱不够，凑满100块再来吧！", new Vector4(0.6f, 0.6f, 0.2f, 1));
            return;
        }
        var text = Instantiate(m_NumberTextPerfab);
        text.text = number.ToString().PadLeft(4, '0'); ;
        text.transform.SetParent(m_BoughtNumberPanel.transform);
        text.transform.localScale = new Vector3(1, 1, 1);


        MessageShow.Instance.Messaage("你买了一注彩票，号码是：" + number);
        Player.Instance.Money -= 100;
        Player.Instance.m_LotteryCurTermNumber = UtilsGame.GetSeedToday();
        Player.Instance.m_LotteryCurTerm.Add(number);
        Player.Instance.save();
    }
}
